package com.tdkj.service.decorate.impl;

import java.sql.Timestamp;

import javax.annotation.Resource;

import org.springframework.stereotype.Component;

import com.tdkj.model.decorate.BeanDiamondCustom;
import com.tdkj.model.decorate.BeanDiamondCustomBuy;
import com.tdkj.model.user.BeanUser;
import com.tdkj.service.BaseService;
import com.tdkj.service.ServiceException;
import com.tdkj.service.decorate.IBeanDiamondCustomBuyService;
import com.tdkj.service.financial.IBeanConsumeRecordService;

@Component
public class BeanDiamondCustomBuyServiceImpl extends BaseService implements
		IBeanDiamondCustomBuyService {

	private IBeanConsumeRecordService consumeRecordService;
	
	@Resource
	public void setConsumeRecordService(
			IBeanConsumeRecordService consumeRecordService) {
		this.consumeRecordService = consumeRecordService;
	}



	@Override
	public void create(Long userId, Long customId) throws ServiceException {
		BeanUser user = this.getBaseDao().findById(userId, BeanUser.class);
		BeanDiamondCustom custom = this.getBaseDao().findById(customId, BeanDiamondCustom.class);
		
		BeanDiamondCustomBuy bean = new BeanDiamondCustomBuy();
		bean.setUser(user);
		bean.setCustom(custom);
		bean.setCreateTime(new Timestamp(System.currentTimeMillis()));
		
		this.getBaseDao().save(bean);
		
		consumeRecordService.create(userId, custom.getPrice(), custom.getUnit(), bean.getId(), BeanDiamondCustomBuy.class, "钻购买");
	}
	
}
